package com.cupk.controller;

import com.cupk.common.PageResult;
import com.cupk.common.Result;
import com.cupk.dto.BorrowSupplyDto;
import com.cupk.dto.ProviderDto;
import com.cupk.dto.ProviderListDto;
import com.cupk.service.ProviderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 名称ProviderController
 * 描述供应商控制类
 *
 * @version 1.0
 * @author:XiongRuiKai
 * @datatime:2023-06-12 10:36
 */
@RestController
@RequestMapping("/provider")
public class ProviderController {
    @Autowired
    private ProviderService providerService;

    /**
     * 供应商申请分页查询
     * @param page 页码
     * @param pageSize 每页返回的数据条目数
     * @param id 供应商编号
     * @param name 供应商姓名
     * @param tele 供应商联系方式
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult<ProviderDto>> getProviderQueryResultsWithPaging
            (@RequestParam(defaultValue = "1") int page,
             @RequestParam(defaultValue = "10") int pageSize,
             @RequestParam(required = false) Integer id,
             @RequestParam(required = false) String name,
             @RequestParam(required = false) String tele
            ) {
        PageResult<ProviderDto> providerDtoPageResult = providerService.
                getQueryResultsWithPaging(id, name, tele, page, pageSize);
        return Result.success(providerDtoPageResult, "Success");
    }


    /**
     * 供应商管理分页查询
     * @param page 页码
     * @param pageSize 每页返回的数据条目数
     * @param id 供应商编号
     * @param providerName 供应商姓名
     * @param tele 供应商联系方式
     * @return
     */
    @GetMapping("/list/page")
    public Result<PageResult<ProviderListDto>>
    getProviderListQueryResultsWithPaging(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) Integer id,
            @RequestParam(required = false) String providerName,
            @RequestParam(required = false) String tele
            ) {
        PageResult<ProviderListDto> providerDtoListPageResult =
                providerService.getListQueryResultsWithPaging(id, providerName, tele, page, pageSize);
        return Result.success(providerDtoListPageResult,"Success");
    }
}
